<?php

class Application_Form_Crewmitglieder extends Zend_Form
{
	protected $_crewmitglieder = array();
	
	public function getCrewmitglieder() {
		return $this->_crewmitglieder;
	}
	
	public function setCrewmitglieder($crewmitglieder){
		$this->_crewmitglieder  = $crewmitglieder;
	}
	
	public function addRow()
	{
		$row_form = new Zend_Form(array(
				'elements' => array(
						/*'one' => array(
								'type' => 'checkbox'
						),*/
						'Name' => array(
								'type' => 'text'
						),
						'Position' => array(
								'type' => 'text'
						),
						'rechttoernedit' => array(
								'type' => 'checkbox'
						),
						'rechtmitgliedeinladen' => array(
								'type' => 'checkbox'
						),
						'rechtlogbuch' => array(
								'type' => 'checkbox'
						),
						'rechtbildhochladen' => array(
								'type' => 'checkbox'
						),
						'rechteinstellungen' => array(
								'type' => 'checkbox'
						),
						'rechtbericht' => array(
								'type' => 'checkbox'
						),
						'loschen' => array(
								'type' => 'checkbox'
						),
						'id' => array(
								'type' => 'hidden'
						),
				),
				'decorators' => array('FormElements', array('HtmlTag', array('tag'=>'tr'))),
				'elementDecorators' => array('ViewHelper', array('HtmlTag', array('tag'=>'td')))
		));
	
		$new_form_index = count($this->_subForms)+1;
		$row_form->setElementsBelongTo($new_form_index);
		$this->addSubform($row_form, $new_form_index);
	
		return $row_form;
	}
	
    public function init()
    {
    	$this->setOptions(array(
    			'elements' => array(
    					'submit' => array(
    							'type' => 'submit',
    					)
    			),
    	));

		//$this->setDecorators(array('FormElements', array('SimpleTable', array('columns' => array('One', 'Name', 'Position'))), 'Form'));

    	$elemente = array();
    	$i = 0;
		foreach($this->_crewmitglieder as $mitglied){
			$row = $this->addRow();
			$row->Name->setValue($mitglied['vorname']);
			$row->Position->setValue($mitglied['positionsname']);
			$row->id->setValue($mitglied['id']);
			$row->rechtlogbuch->setValue($mitglied['rechtlogbuch']);
			$row->rechttoernedit->setValue($mitglied['rechttoernedit']);
			$row->rechtmitgliedeinladen->setValue($mitglied['rechtmitgliedeinladen']);
			$row->rechtbildhochladen->setValue($mitglied['rechtbildhochladen']);
			$row->rechteinstellungen->setValue($mitglied['rechteinstellungen']);
			$row->rechtbericht->setValue($mitglied['rechtbericht']);

// 			$elemente[$i]->populate(array(
// 				'Name' => $mitglied['vorname']
// 			));
		}
		
		
		$this->getElement('submit')->setDecorators(array('ViewHelper', array(array('td'=>'HtmlTag'), array('tag'=>'td', 'colspan'=>3)), array(array('tr'=>'HtmlTag'), array('tag'=>'tr'))));
		$this->getElement('submit')->setOrder(100);
    	
    	
    	
    	/*
        $form = new Zend_Form();
		$form->setMethod('post')
		     ->setAttrib('id', 'contactForm');
		$subForm = new Zend_Form_SubForm();
		
		foreach($array as $rownum => $row){
		  $id = $row['id'];
		  $rowForm = new Zend_Form_SubForm();
		  foreach($row as $key => $value){
		    if($key == 'id') continue;
		    $rowForm->addElement(
		      'text',
		      $key,
		      array(
		        'value' => $value,
		      )
		    );
		  }
		  $rowForm->setElementDecorators(array(
		    'ViewHelper',
		    'Errors',
		    array('HtmlTag', array('tag' => 'td')),
		  ));
		  $subForm->addSubForm($rowForm, $id);
		}
		
		$subForm->setSubFormDecorators(array(
		  'FormElements',
		  array('HtmlTag', array('tag'=>'tr')),
		));
		
		$form->addSubForm($subForm, 'contacts');
		
		$form->setSubFormDecorators(array(
		  'FormElements',
		  array('HtmlTag', array('tag' => 'tbody')),
		));
		
		$form->setDecorators(array(
		    'FormElements',
		    array('HtmlTag', array('tag' => 'table')),
		    'Form'
		));
		
		$form->addElement(
		  'submit', 'submit', array('label' => 'Submit'));
		
		$form->submit->setDecorators(array(
		    array(
		        'decorator' => 'ViewHelper',
		        'options' => array('helper' => 'formSubmit')),
		    array(
		        'decorator' => array('td' => 'HtmlTag'),
		        'options' => array('tag' => 'td', 'colspan' => 4)
		        ),
		    array(
		        'decorator' => array('tr' => 'HtmlTag'),
		        'options' => array('tag' => 'tr')),
		));
		*/
    }


}

